class Solution {
public:



    bool canFinish(int numCourses, vector<vector<int>>& vv) 
    {

        //建图, 建入度表
        unordered_map<int, vector<int>> miv;
        vector<int> in(numCourses, 0);

        for(auto &e: vv)
        {
            //b -> a;学a先学b
            int a = e[0], b = e[1];
            in[a]++;

            miv[b].push_back(a);
        }

        queue<int> que;
        for(int i=0; i<numCourses; i++) if(in[i] == 0) que.push(i);

        while(que.size())
        {
            int val = que.front();
            que.pop();

            for(auto e: miv[val])
            {
                in[e]--;
                if(in[e] == 0) que.push(e);
            }
        }

        for(auto e: in) if(e != 0) return false;

        return true;
    }
};